/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Project: javaseapp - Ex1
 * <p>Powered by webrx On 2021-08-25 08:41:38
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Ex1 {
    //可见性，设置的对象，允许多个线程可见
    volatile List<String> list = new ArrayList<String>();

    public void add() {
        String tn = Thread.currentThread().getName();
        list.add("item" + (list.size() + 1));
        System.out.println(String.format("%s:%d = %s", tn, list.size(), list.get(list.size() - 1)));
    }

    public boolean check() {
        boolean f = false;
        if (list.size() >= 5) {
            f = true;
        }
        return f;
    }
}
